package com.sdy.dao.mysql;

import com.sdy.po.Menu;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;

import java.util.List;

@Mapper
public interface ManageMenuMapper {

    /**
     * 查询所有菜单模块
     * @return
     */
    @Select("select * from s_manage_menu")
    @Results({
            @Result(column = "id",property = "id"),
            @Result(column = "id", property = "authority", one = @One(select = "com.sdy.dao.mysql.AuthorityMapper.selectAuthorityByMenuId", fetchType = FetchType.EAGER))
    })
    List<Menu> selectAllMenu();

    /**
     * 根据权限查询菜单模块
     * @return
     */
    @Select("select * from s_manage_menu where customer=1")         //客户
    List<Menu> selectMenuByCustomer();
    @Select("select * from s_manage_menu where technicalAdmin=1")   //技术管理员
    List<Menu> selectMenuByTechnicalAdmin();
    @Select("select * from s_manage_menu where systemAdmin=1")      //系统管理员
    List<Menu> selectMenuBySystemAdmin();
    @Select("select * from s_manage_menu where salesAdmin=1")       //销售管理员
    List<Menu> selectMenuBySalesAdmin();

    @Insert("insert into s_manage_menu (name,urle,whiteImage,blackImage,customer,technicalAdmin,systemAdmin,salesAdmin) " +
            "values (#{menu.name},#{menu.urle},#{menu.whiteImage},#{menu.blackImage},#{menu.customer},#{menu.technicalAdmin},#{menu.systemAdmin},#{menu.salesAdmin})")
    Boolean insertOneMenu(Menu menu);

    @Update("update s_manage_menu set name=#{menu.name} where id=#{menu.id}")
    Boolean updateOneMenu(Menu menu);

    @Delete("delete from s_manage_menu where id=#{id} ")
    Boolean deleteOneMenuById(Integer id);
}
